/****************************************
 * chatter_serv.h
 */

#define _DEBUG_CHATTER_SERV

#ifndef	_CHATTER_SERV_H
#define	_CHATTER_SERV_H

#include <stdlib.h>
#include <mysql.h>
#include <pthread.h>
#include "chatter_global.h"


#define FUNC_NUM 12

extern pthread_mutex_t database_mutex;
extern MYSQL *conn;

typedef struct
{
	unsigned char	index;										//FLAG MIRCOS delcear in "chatter_global.h"
	int				(*fptr)(int sockfd, char *body, short len);			//function pointer
}func_index_t;


/**** user interfaces ***********/

int		query_db(const char *QueryStatement, MYSQL_RES **res, int *num_row, int *num_field , long *affact_row);
		//return: succ-->0; fail--> -1
		//Just leave the last 3 parameters NULL if don't need them
int		send_succ_or_err(const int sockfd,const unsigned char flagtype, const char *errstr, const size_t str_len);
		//send an succ ,OR error packet to client
void *	ctrl_center(void * arg);
		//threads start here
int		func_index_init(func_index_t *func_index);

/*********************************************************************************\
 * every function below should call send_succ_or_err() it self, and return an
 * negative number to ctrl_center() , and ctrl_center will write in log or
 * print the error by calling  err_msg()
\*********************************************************************************/

int		serv_hello( int sockfd, char *body ,short len);
int		serv_login( int sockfd, char *body, short len);
int		serv_logout( int sockfd, char *body, short len);
int		serv_message( int sockfd, char *body, short len);
int		serv_request_buddy_list( int sockfd, char *body, short len);
int		serv_search_num( int sockfd, char *body, short len);
int		serv_search_nick( int sockfd, char *body, short len);
int		serv_add_a_buddy( int sockfd, char *body, short len);
int		serv_del_a_buddy( int sockfd, char *body, short len);
int		serv_set_detail( int sockfd, char *body, short len);
int		serv_register( int sockfd, char *body, short len);
int		serv_set_nick( int sockfd, char *body, short len);

#endif /* _CHATTER_SERV_H */
